package com.gscitysfy.cus.drain.modules.duty.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gscitysfy.cloudfrmwk.assistant.domain.Result;

import com.gscitysfy.cus.drain.annotations.DictTranslation;
import com.gscitysfy.cus.drain.annotations.FieldParam;
import com.gscitysfy.cus.drain.constants.DicConstant;
import com.gscitysfy.cus.drain.modules.duty.entity.MoperDutyMnClasses;
import com.gscitysfy.cus.drain.modules.duty.service.IMoperDutyMnClassesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Administrator
 * @since 2022-03-29 15:06:16
 */
@RestController
@RequestMapping("/duty/classess")
public class MoperDutyMnClassesController {
    @Autowired
    IMoperDutyMnClassesService moperDutyMnClassesService;

    /**
     * 新增
     *
     * @param moperDutyMnClassess
     * @return
     */
    @PostMapping("/add")
    public Result add(MoperDutyMnClasses moperDutyMnClassess) {
            return Result.success(moperDutyMnClassesService.addMoperDutyMnClasses(moperDutyMnClassess));
    }


    /**
     * 修改
     *
     * @param moperDutyMnClassess
     * @return
     */
    @PostMapping("/update")
    public Result update(MoperDutyMnClasses moperDutyMnClassess) {
        int i = moperDutyMnClassesService.updateMoperDutyMnClasses(moperDutyMnClassess);
        if (i > 0) {
            return Result.success();
        } else {
            return Result.failure();
        }
    }


    /**
     * 删除
     */
    @PostMapping("/delete")
    public Result delete(String ids) {
        if (moperDutyMnClassesService.deleteMoperDutyMnClasses(ids)) {
            return Result.success();
        } else {
            return Result.failure("所选班次已关联，请重新选择");
        }
    }


    /**
     * 详情
     */
    @GetMapping("/detail")
    @DictTranslation({@FieldParam(dictType = DicConstant.DUTY_TYPE, targetField = "coamClassessType")})
    public Result detail(String id) {
        MoperDutyMnClasses moperDutyMnClasses = moperDutyMnClassesService.detailMoperDutyMnClasses(id);
        return Result.content(moperDutyMnClasses);

    }


    /**
     * 列表
     *
     * @return
     */
    @GetMapping("/all")
    @DictTranslation({@FieldParam(dictType = DicConstant.DUTY_TYPE, targetField = "coamClassessType")})
    public Result getAll(Page<MoperDutyMnClasses> page, Integer coamClassessStatu, String coamDutyType,String coamClassessCode) {
        return Result.content(moperDutyMnClassesService.getAll(page, coamClassessStatu, coamDutyType,coamClassessCode));
    }

    /**
     * 获取正在启用的值班长班次数目
     * @return
     */
    @GetMapping("/getEnableLeaderClass")
    public Result getEnableLeaderClass(){
        return Result.content(moperDutyMnClassesService.getEnableLeaderClass());
    }

}
